home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
7_8.lha
/
7_8
/
7_8a5.h
< prev
next >
Wrap
Text File
|
1993-08-08
|
4KB
|
195 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
define gdlistimplement(TYPE) \
/* clear the list */ \
void gdlist(TYPE)::clear() \
{ \
gdlink(TYPE) *l = last; \
if (!l) return; \
\
do { \
gdlink(TYPE) *ll = l; \
l = l->next; \
delete ll; \
} while (l != last); \
\
last = 0; \
} \
\
/* Get the next entry from a list, */ \
/* moving curr forward. */ \
int gdlist(TYPE)::next(TYPE &a) \
{ \
if (!last) \
return 0; \
\
/* move curr forward, possibly to */ \
/* the beginning or end of the list. */ \
if (curr) \
if (curr == last) \
{ \
curr = 0; \
return 0; \
} \
\
else \
curr = curr->next; \
\
else \
curr = last->next; \
\
a = curr->e; \
return 1; \
} \
\
/* Get the previous entry from a list, */ \
/* moving curr backwards. */ \
int gdlist(TYPE)::prev(TYPE &a) \
{ \
if (!last) \
return 0; \
\
/* move curr backwards, possibly to */ \
/* the beginning or end of the list. */ \
if (curr) \
if (curr == last->next) \
{ \
curr = 0; \
return 0; \
} \
\
else \
curr = curr->prev; \
\
else \
curr = last; \
\
a = curr->e; \
return 1; \
} \
\
/* Get the next entry from a list, */ \
/* removing it afterwards. */ \
/* curr is left alone. */ \
int gdlist(TYPE)::getnext(TYPE &a) \
{ \
if (!last) \
return 0; \
\
/* choose the link to remove */ \
gdlink(TYPE) *f; \
if (curr) \
if (curr == last) \
{ \
curr = 0; \
return 0; \
} \
\
else \
f = curr->next; \
\
else \
f = last->next; \
\
a = f->e; \
\
/* remove f from the list */ \
if (f == last) \
last = 0; \
\
else \
f->remove(); \
\
delete f; \
return 1; \
} \
\
/* Get the previous entry from a list, */ \
/* removing it afterwards */ \
int gdlist(TYPE)::getprev(TYPE &a) \
{ \
if (!last) \
return 0; \
\
/* choose the link to remove */ \
gdlink(TYPE) *f; \
if (curr) \
if (curr == last->prev) \
{ \
curr = 0; \
return 0; \
} \
\
else \
f = curr->prev; \
\
else \
curr = last; \
\
a = f->e; \
\
/* remove f from the list */ \
if (f == last) \
last = 0; \
\
else \
f->remove(); \
\
delete f; \
return 1; \
} \
\
/* insert an entry at the */ \
/* beginning of the list */ \
void gdlist(TYPE)::insert(TYPE a) \
{ \
if (last) \
last->next-> \
insert(new gdlink(TYPE)(a)); \
\
else \
{ \
last = new gdlink(TYPE)(a); \
last->next = last->prev = last; \
} \
} \
\
/* Append an entry at the end of the */ \
/* list. This is the same as */ \
/* gdlist(TYPE)::insert() */ \
/* except that gdlist(TYPE)::last is */ \
/* adjusted afterwards. */ \
void gdlist(TYPE)::append(TYPE a) \
{ \
this->insert(a); \
last = last->next; \
} \
\
/* Insert an entry before the */ \
/* current location of the list. */ \
/* If curr is not set, insert at */ \
/* the beginning of the list. */ \
void gdlist(TYPE)::inserthere(TYPE a) \
{ \
if (curr) \
curr->insert(new gdlink(TYPE)(a)); \
\
else \
this->insert(a); \
} \
\
/* Append an entry after the */ \
/* current location of the list. */ \
/* If curr is not set, append at */ \
/* the end of the list. */ \
void gdlist(TYPE)::appendhere(TYPE a) \
{ \
if (curr) \
curr->append(new gdlink(TYPE)(a)); \
\
else \
this->append(a); \
}